package StacksAndQueues;

import java.util.LinkedList;
import java.util.Queue;

public class lc225 {
    
}
class MyStack {

    Queue<Integer> que;

    public MyStack() {
        que = new LinkedList<>();
    }
    
    public void push(int x) {
        que.offer(x);
    }
    
    public int pop() {
        rePosition();
        return que.poll();
    }
    
    public int top() {
        rePosition();
        int res = que.poll();
        que.offer(res);
        return res;
    }
    
    public boolean empty() {
        return que.isEmpty();
    }

    public void rePosition(){
        int size = que.size();
        size--;
        while (size-->0) {
            que.offer(que.poll());
        }
    }
}

/**
 * Your MyStack object will be instantiated and called as such:
 * MyStack obj = new MyStack();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.top();
 * boolean param_4 = obj.empty();
 */